using Volo.Abp;
using Volo.Abp.Modularity;
using Volo.Abp.Application;
using Volo.Abp.AutoMapper;
using Volo.Abp.FluentValidation;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Caching;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection;
using Matrix.Configuration.Contracts;
using Matrix.Configuration.Application;
using Matrix.Configuration.Application.Services;

namespace Matrix.Configuration
{
    [DependsOn(
        typeof(MatrixConfigurationDomainModule),
        typeof(MatrixConfigurationApplicationContractsModule),
        typeof(AbpDddApplicationModule),
        typeof(AbpAutoMapperModule),
        typeof(AbpFluentValidationModule),
        typeof(AbpCachingModule)
    )]
    public class MatrixConfigurationApplicationModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            // AutoMapper配置
            context.Services.AddAutoMapperObjectMapper<MatrixConfigurationApplicationModule>();
            Configure<AbpAutoMapperOptions>(options =>
            {
                options.AddMaps<MatrixConfigurationApplicationModule>();
            });

            // 注册类型化缓存支持
            // 暂时禁用Redis缓存配置，避免缺少包引用问题
            // context.Services.AddStackExchangeRedisCache(options =>
            // {
            //     options.Configuration = "localhost:6379";
            // });

            // 注册分离后的应用服务（接口和实现类）
            context.Services.AddTransient<Matrix.Configuration.Contracts.IConfigurationQueryService, ConfigurationQueryService>();
            context.Services.AddTransient<Matrix.Configuration.Contracts.IConfigurationCommandService, ConfigurationCommandService>();
            // 重新启用缓存服务
            context.Services.AddTransient<Matrix.Configuration.Contracts.IConfigurationCacheService, ConfigurationCacheService>();

            // 注册协调器服务
            context.Services.AddTransient<Matrix.Configuration.Contracts.IConfigurationAppService, ConfigurationAppService>();
        }
    }
}